package org.datascooter.parser;

import java.lang.reflect.InvocationTargetException;

import org.datascooter.exception.EntityNotMappedException;
import org.datascooter.inface.IProvider;
import org.datascooter.inface.IXMLReader;

public abstract class AbstractProvider<T> implements IProvider<T> {

	protected final IXMLReader[] readerArray;

	public AbstractProvider(IXMLReader... readerArray) {
		this.readerArray = readerArray;
	}

	protected abstract void processRoot(IXMLReader element) throws EntityNotMappedException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException;

	@Override
	public void explore() throws EntityNotMappedException {
		for (IXMLReader reader : readerArray) {
			try {
				reader.explore();
				for (IXMLReader element : reader.getChildren(null)) {
					processRoot(element);
				}
			} catch (Exception e) {
				throw new EntityNotMappedException("***Error by parsing file: ", e);
			}
		}
	}
}
